import type { AppRouteRecordRaw, AppRouteModule } from '/@/router/types';

import { PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '/@/router/routes/basic';

import { mainOutRoutes } from './mainOut';
import { t } from '/@/hooks/web/useI18n';

const modules = import.meta.glob('./modules/**/*.ts', { eager: true });

const routeModuleList: AppRouteModule[] = [];

// 加入到路由集合中
Object.keys(modules).forEach((key) => {
  const mod = (modules as Recordable)[key].default || {};
  const modList = Array.isArray(mod) ? [...mod] : [mod];
  routeModuleList.push(...modList);
});

export const asyncRoutes = [PAGE_NOT_FOUND_ROUTE, ...routeModuleList];

// 博客路由配置
export const BlogRoute: AppRouteRecordRaw = {
  path: '/blog',
  name: 'Blog',
  component: () => import('/@/layouts/blog/index.vue'),
  redirect: '/blog/about',
  meta: {
    hideChildrenInMenu: true,
    icon: 'simple-icons:blog',
    title: '博客',
    orderNo: 100000,
    ignoreAuth: true, // 博客相关页面不需要登录验证
  },
  children: [
    {
      path: 'about',
      name: 'BlogAbout',
      component: () => import('/@/views/blog/about/index.vue'),
      meta: {
        title: '关于我',
        icon: 'simple-icons:about-dot-me',
        hideMenu: true,
        ignoreAuth: true,
      },
    },
    {
      path: 'articles',
      name: 'BlogArticles',
      component: () => import('/@/views/blog/articles/index.vue'),
      meta: {
        title: '技术文档',
        icon: 'simple-icons:book',
        hideMenu: true,
        ignoreAuth: true,
      },
    },
    {
      path: 'articles/:id',
      name: 'BlogArticlesDetail',
      component: () => import('/@/views/blog/articles/components/BlogArticlesDetail.vue'),
      meta: {
        title: '文档详情',
        hideMenu: true,
        ignoreAuth: true,
      },
    },
    {
      path: 'contact',
      name: 'BlogContact',
      component: () => import('/@/views/blog/contact/index.vue'),
      meta: {
        title: '联系我',
        icon: 'simple-icons:contact',
        hideMenu: true,
        ignoreAuth: true,
      },
    },
    {
      path: 'scripts',
      name: 'BlogScripts',
      component: () => import('/@/views/blog/scripts/index.vue'),
      meta: {
        title: '快捷脚本',
        icon: 'simple-icons:scripts',
        hideMenu: true,
        ignoreAuth: true,
      },
    },
    {
      path: 'scripts/:id',
      name: 'BlogScriptsDetail',
      component: () => import('/@/views/blog/scripts/components/BlogScriptsDetail.vue'),
      meta: {
        title: '脚本详情',
        hideMenu: true,
        ignoreAuth: true,
      },
    },
    {
      path: 'message',
      name: 'BlogMessage',
      component: () => import('/@/views/blog/message/index.vue'),
      meta: {
        title: '留言板',
        icon: 'simple-icons:message',
        hideMenu: true,
        ignoreAuth: true,
      },
    },
  ],
};

export const RootRoute: AppRouteRecordRaw = {
  path: '/',
  name: 'Root',
  component: () => import('/@/views/index/index.vue'),
  meta: {
    title: 'Root',
    ignoreAuth: true,
  },
};

export const LoginRoute: AppRouteRecordRaw = {
  path: '/login',
  name: 'Login',
  //新版后台登录，如果想要使用旧版登录放开即可
  component: () => import('/@/views/sys/login/Login.vue'),
  //component: () => import('/@/views/system/loginmini/MiniLogin.vue'),
  meta: {
    title: t('routes.basic.login'),
  },
};

//update-begin---author:wangshuai ---date:20220629  for：auth2登录页面路由------------
export const Oauth2LoginRoute: AppRouteRecordRaw = {
  path: '/oauth2-app/login',
  name: 'oauth2-app-login',
  //新版钉钉免登录，如果想要使用旧版放开即可
  // component: () => import('/@/views/sys/login/OAuth2Login.vue'),
  component: () => import('/@/views/system/loginmini/OAuth2Login.vue'),
  meta: {
    title: t('routes.oauth2.login'),
  },
};
//update-end---author:wangshuai ---date:20220629  for：auth2登录页面路由------------

/**
 * 【通过token直接静默登录】流程办理登录页面 中转跳转
 */
export const TokenLoginRoute: AppRouteRecordRaw = {
  path: '/tokenLogin',
  name: 'TokenLoginRoute',
  component: () => import('/@/views/sys/login/TokenLoginPage.vue'),
  meta: {
    title: '带token登录页面',
    ignoreAuth: true,
  },
};

export const IndexRoute: AppRouteRecordRaw = {
  path: '/index',
  name: 'Index',
  component: () => import('/@/views/index/index.vue'),
  meta: {
    title: t('routes.basic.index'),
    ignoreAuth: true,
  },
};

// Basic routing without permission
export const basicRoutes = [
  LoginRoute,
  RootRoute,
  BlogRoute,
  ...mainOutRoutes,
  REDIRECT_ROUTE,
  PAGE_NOT_FOUND_ROUTE,
  TokenLoginRoute,
  Oauth2LoginRoute,
];
